package cn.bugDance.domain.strategy.service.rule.chain.impl;

import cn.bugDance.domain.strategy.model.entity.RaffleFactorEntity;
import cn.bugDance.domain.strategy.model.valobj.StrategyConstant;
import cn.bugDance.domain.strategy.service.dispatch.IRaffleStrategyDispatch;
import cn.bugDance.domain.strategy.service.rule.chain.AbstractRuleChain;
import cn.bugDance.domain.strategy.service.rule.chain.factory.RuleChainFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component(StrategyConstant.StrategyRule.RULE_BACK_STOP)
@Slf4j
public class RuleBackStopChain extends AbstractRuleChain {

    @Resource
    private IRaffleStrategyDispatch raffleStrategyDispatch;

    @Override
    public RuleChainFactory.RuleChainActionEntity action(RaffleFactorEntity raffleFactorEntity) {

        Long strategyId = raffleFactorEntity.getStrategyId();
        String userId = raffleFactorEntity.getUserId();
        log.info("【策略领域层-RuleBlackListChain】: 开启兜底责任链执行, strategyId: {}, userId: {}", strategyId, userId);

        Integer awardId = raffleStrategyDispatch.randomRaffle(strategyId);
        log.info("【策略领域层-RuleWeightChain】: 兜底责任链拦截, strategyId: {}, awardId: {}", strategyId, awardId);
        return RuleChainFactory.RuleChainActionEntity.builder()
                .strategyId(strategyId)
                .awardId(awardId).build();
    }
}
